package com.web.model;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
import org.apache.log4j.Logger;

import java.util.Date;
import java.util.List;

/**
 * Created by reeveslee on 16/7/3.
 */
public class Records extends Model<Records> {
    private static final Logger LOGGER = Logger.getLogger(Records.class);
    public static Records recordsDao = new Records();

    public List<Records> getUserRecords(int userId) {
        String sql = "select type,hour,minute,second,time from v1_grass_record where userId=?";
        return recordsDao.find(sql, userId);
    }

    public long addUserRecords(int userId, String record_type, int hour, int minute, int second) {
        Records records = new Records();
        records.set("userId", userId).set("type", record_type).set("hour", hour).set("minute", minute).set("second", second).set("time", new Date()).save();
        return records.get("id");
    }

    public List<Record> getUserCountData(int userId) {
        String sql = "select type,sum(value) as value from v1_grass_launchcard where userId=? group by type";
        return Db.find(sql, userId);
    }

}
